package com.sl.ms.carriage.handler;

import com.sl.ms.base.api.common.AreaFeign;
import com.sl.ms.carriage.domain.dto.WaybillDTO;
import com.sl.ms.carriage.entity.CarriageEntity;
import com.sl.ms.carriage.service.CarriageService;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * description:
 *
 * @Author youhongwei
 * @Create 2025/6/23 20:24
 * @Version 1.0
 */
@Order(300)
@Component
public class EconomicZoneChainHandler extends AbsCarriageChainHandler{

    @Resource
    private CarriageService carriageService;

    @Resource
    private AreaFeign areaFeign;

    /**
     * 经济区
     * @param waybillDTO
     * @return
     */
    @Override
    public CarriageEntity doHandler(WaybillDTO waybillDTO) {

//        CarriageEntity carriageEntity = null;
        Long receiverParentId = areaFeign.get(waybillDTO.getReceiverCityId()).getParentId();
        Long senderParentId = areaFeign.get(waybillDTO.getSenderCityId()).getParentId();

        CarriageEntity carriageEntity = this.carriageService.findEconomicCarriage(receiverParentId,senderParentId);

        if(carriageEntity != null){
            return carriageEntity;
        }


        return doNextHandler(waybillDTO);
    }
}
